package com.javasm.JDBC;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class JDBCTest {
    public static void main(String[] args) {
        try {
            // 加载 MySQL 驱动
            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/testdb", "root", "123456");
            System.out.println("数据库连接成功！");
            //创建一个可执行的对象
            Statement st = conn.createStatement();
            //要执行的sql语句
            String  sql = "select * from admin_menu";
            ResultSet resultSet = st.executeQuery(sql);

            while (resultSet.next()){
                int  id =resultSet.getInt("mid");
                String name =resultSet.getString("menuname");
                System.out.println("id是" + id + ", name是" + name);
            }
            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}